/*
 * ZENworks Notification Icon
 * Copyright (C) Author: Gangadhar Nagesh Metla (Novell, Inc.)
 * nmetla74@gmail.com 
 * Version 1.0
 * 1/3/2009
 * Filename PageApp.java
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.novell.zenworks.agent.zicon;

import java.io.File;

import com.novell.zenworks.agent.common.Paths;
import com.novell.zenworks.agent.zbrowser.ZBrowser;

public class PageApp
{
    public static final String PROPERTY = "property";
    public static final String DATAFORM = "dataform";
    public static ZBrowser browser = null;
    public static ZBrowser dataform = null;
    
    public static void launchBrowser(String pageId) throws Exception
    {
        ZTrayIcon.getServer(); //check the server availability
        if(browser == null)
        {
            browser = new ZBrowser(null, Paths.RESOURCE_DIR + File.separator + "images", ZTrayIcon.rm.getString("PropDlgTitle"), "http", "localhost", -1, pageId, PROPERTY, -1);
        }
        else
        {
            browser.unIconify();
        }
    }
    
    public static void launchDataform(String pageId, int timeout) throws Exception
    {
        ZTrayIcon.getServer(); //check the server availability
        if(dataform == null)
        {
            dataform = new ZBrowser(null, Paths.RESOURCE_DIR + File.separator + "images", ZTrayIcon.rm.getString("CdfDlgTitle"), "http", "localhost", -1, pageId, DATAFORM, timeout);
        }
        else
        {
            dataform.unIconify();
        }
    }    
    
    public static void nullifyBrowser()
    {
        ZTrayIcon.propertyPage.setId(browser.getPage().getId());
        browser.dispose();
        browser = null;
    }
    
    public static void nullifyDataform()
    {
        dataform.dispose();
        dataform = null;
    }
    
    public static void setDefaultPage()
    {
    	ZTrayIcon.propertyPage.setId("Status");
    }
    
    public static void refreshPage() throws Exception
    {
    	if(browser != null)
    	{
    		browser.refreshPage();
    	}
    	
    	if(dataform != null)
    	{
    		browser.refreshPage();
    	}
    	
    }
}
